package Test;

import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

/**
 * @Auther: lizhipeng
 * @Date: 2024-10-08 - 10 - 08 - 11:32
 * @Description: Test
 * @version: 1.0
 */
public class Student implements Comparable<Student> {
    private int age ;
//    public int weight;
    private String name;

    public Student(int age , String name){
        this.age = age;
        this.name  = name;
    }

    public static void main(String[] args) {
        TreeMap<Student,String> map = new TreeMap<>(new StuentCompartor());
        Student student1 = new Student(21,"江流儿");
        Student student2 = new Student(19,"棋鬼王");
        Student student3 = new Student(22,"方百花");
        Student student4 = new Student(37,"幽王");
        map.put(student1 , "1");
        map.put(student2 ,"2" );
        map.put(student3 , "3");
        map.put(student4 ,"4" );
        Set<Map.Entry<Student,String>> entries = map.entrySet();
        for( Map.Entry<Student,String> entry :entries){
            System.out.println(entry);
        }

    }
    @Override
    public int compareTo(Student stu) {
        if(this.age < stu.age){
            return -1;
        }
        else if(this.age > stu.age){
            return 1;
        }
        return 0;
    }

    public int getAge() {
        return age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                ", name='" + name + '\'' +
                '}';
    }
}
